home *** CD-ROM | disk | FTP | other *** search
/ Champak 125 / Vol 125 (Damaged).iso / games / rabbit_r.swf / scripts / __Packages / disney / rabbitRivalry / ents / Tree.as < prev    next >
Encoding:
Text File  |  2009-06-09  |  4.8 KB  |  151 lines

  1. class disney.rabbitRivalry.ents.Tree extends disney.rabbitRivalry.ents.Entity
  2. {
  3.    var __baseY;
  4.    var __trunkHeight;
  5.    var startY;
  6.    var isDrawn;
  7.    var __xOnscreen;
  8.    var x;
  9.    var scale;
  10.    var baseWidth;
  11.    var mc;
  12.    var y;
  13.    var __fastScale;
  14.    var z;
  15.    var startScale;
  16.    var baseHeight;
  17.    var isTreeTopDrawn;
  18.    var isTreeTrunkDrawn;
  19.    var hdWidth;
  20.    var hdReg;
  21.    var TYPE = "tree";
  22.    var DRAWTYPE = "trees";
  23.    var __DEF_ASSET = "_empty";
  24.    var __DEF_WIDTH = 521;
  25.    var __DEF_HEIGHT = 93;
  26.    var __USE_ACTUAL_DIMENSIONS = false;
  27.    var __USE_DIMENSIONS_AS_HD = true;
  28.    var __TREETOP_ASSET = "treetop_mc";
  29.    var __TREETRUNK_ID = "treetrunk_mc";
  30.    var __TRUNK_WIDTH_HALF = 125;
  31.    var __SHADOW_START = 80;
  32.    var __SHADOW_WIDTH = 40;
  33.    var __TREETOP_HEIGHT = 50;
  34.    function Tree(t_data)
  35.    {
  36.       super(t_data);
  37.       if(t_data.ground == undefined)
  38.       {
  39.          this.__baseY = 700;
  40.       }
  41.       else
  42.       {
  43.          this.__baseY = t_data.ground;
  44.       }
  45.       this.__baseY -= 23;
  46.       this.__trunkHeight = this.__baseY - this.startY;
  47.    }
  48.    function updateAnim()
  49.    {
  50.    }
  51.    function render(camera, dt)
  52.    {
  53.       if(!this.isDrawn)
  54.       {
  55.          this.updateDraw(camera);
  56.       }
  57.       this.__xOnscreen = Math.abs((this.x - camera.x) * this.scale) < camera.sc.x + this.baseWidth;
  58.       this.renderTreeTrunk(camera,this.__xOnscreen);
  59.       this.renderTreeTop(camera,this.__xOnscreen);
  60.       this.mc._x = Math.ceil(((this.x - camera.x) * this.scale + camera.sc.x) * 100) / 100;
  61.       this.mc._y = Math.ceil(((this.y - camera.y) * this.scale + camera.sc.y) * 100) / 100;
  62.       this.__fastScale = camera.fl / (this.z - camera.z);
  63.       if(this.scale != this.__fastScale)
  64.       {
  65.          this.scale = this.__fastScale;
  66.          this.mc._xscale = this.mc._yscale = 100 * (1 + (this.scale - this.startScale));
  67.       }
  68.    }
  69.    function renderTreeTop(camera, xOnscreen)
  70.    {
  71.       if(xOnscreen && Math.abs((this.y - camera.y) * this.scale) < camera.sc.y + this.baseHeight)
  72.       {
  73.          if(!this.isTreeTopDrawn)
  74.          {
  75.             this.mc.attachMovie(this.__TREETOP_ASSET,this.__TREETOP_ASSET,2);
  76.             this.mc[this.__TREETOP_ASSET].cacheAsBitmap = true;
  77.             this.isTreeTopDrawn = true;
  78.          }
  79.       }
  80.       else if(this.isTreeTopDrawn)
  81.       {
  82.          this.mc[this.__TREETOP_ASSET].removeMovieClip();
  83.          this.isTreeTopDrawn = false;
  84.       }
  85.    }
  86.    function renderTreeTrunk(camera, xOnscreen)
  87.    {
  88.       if(xOnscreen)
  89.       {
  90.          if(!this.isTreeTrunkDrawn)
  91.          {
  92.             var _loc2_ = this.mc.createEmptyMovieClip(this.__TREETRUNK_ID,1);
  93.             var _loc3_ = 8480297;
  94.             if(disney.rabbitRivalry.GameState.getInstance().levelNum > 5)
  95.             {
  96.                _loc3_ = 4930840;
  97.             }
  98.             _loc2_.lineStyle(1,_loc3_,100);
  99.             _loc2_.beginFill(_loc3_,100);
  100.             _loc2_.moveTo(- this.__TRUNK_WIDTH_HALF,this.__trunkHeight);
  101.             _loc2_.lineTo(this.__TRUNK_WIDTH_HALF,this.__trunkHeight);
  102.             _loc2_.lineTo(this.__TRUNK_WIDTH_HALF,this.__TREETOP_HEIGHT);
  103.             _loc2_.lineTo(- this.__TRUNK_WIDTH_HALF,this.__TREETOP_HEIGHT);
  104.             _loc2_.lineTo(- this.__TRUNK_WIDTH_HALF,this.__trunkHeight);
  105.             _loc3_ = 7954728;
  106.             if(disney.rabbitRivalry.GameState.getInstance().levelNum > 5)
  107.             {
  108.                _loc3_ = 5982494;
  109.             }
  110.             _loc2_.beginFill(_loc3_,100);
  111.             _loc2_.moveTo(this.__SHADOW_START,this.__trunkHeight);
  112.             _loc2_.lineTo(this.__SHADOW_START + this.__SHADOW_WIDTH,this.__trunkHeight);
  113.             _loc2_.lineTo(this.__SHADOW_START + this.__SHADOW_WIDTH,this.__TREETOP_HEIGHT);
  114.             _loc2_.lineTo(this.__SHADOW_START,this.__TREETOP_HEIGHT);
  115.             _loc2_.lineTo(this.__SHADOW_START,this.__trunkHeight);
  116.             _loc2_.cacheAsBitmap = true;
  117.             this.isTreeTrunkDrawn = true;
  118.          }
  119.       }
  120.       else if(this.isTreeTrunkDrawn)
  121.       {
  122.          this.mc[this.__TREETRUNK_ID].removeMovieClip();
  123.          this.isTreeTrunkDrawn = false;
  124.       }
  125.    }
  126.    function updateDraw(camera)
  127.    {
  128.       smashing.keithm.Viewport.getInstance().draw({element:this});
  129.       this.isTreeTopDrawn = false;
  130.       this.isTreeTrunkDrawn = false;
  131.    }
  132.    function runHD(player)
  133.    {
  134.       if(player.nextX > this.x - this.hdWidth && player.nextX < this.x + this.hdWidth)
  135.       {
  136.          if(player.velocity.y > 0 && player.y < this.y + 45 && player.nextY >= this.y)
  137.          {
  138.             trace("Tree collision : " + this.y);
  139.             return true;
  140.          }
  141.       }
  142.       return false;
  143.    }
  144.    function setHDRegistration()
  145.    {
  146.       this.hdReg = {};
  147.       this.hdReg.x = 0;
  148.       this.hdReg.y = 0;
  149.    }
  150. }
  151.